package top.zt9.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.zt9.service.ElasticsearchService;

import java.io.IOException;

/**
 * @Author ztf
 * @Date 9:28 2021/11/27
 **/
@Component
public class SendLogListener {
    @Autowired
    private ElasticsearchService elasticsearchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_SMS_SEND_LOG)
    public void sendLog(StandardSubmit standardSubmit , Channel channel, Message message) throws IOException {

        //保存对象到es服务
        elasticsearchService.saveLog(standardSubmit);

        //手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
